﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace X9Tech.HashWall.Core.Simulation
{
    public class MessageSimulator
    {
        private Messaging.MessagingManager mMgr = null;
        internal MessageSimulator(Messaging.MessagingManager manager)
        {
            mMgr = manager;
        }

        private bool simulationActive = false;
        public bool Active
        {
            get { return simulationActive; }
        }

        public void StartSimulation()
        {
            simulationActive = true;
        }

        public void StopSimulation()
        {
            simulationActive = false;
        }

        internal void DoSimulationIfNecessary()
        {
            if (simulationActive)
            {
                GenerateRandomMessage();
            }
        }

        public void GenerateRandomMessage()
        {
            string[] names = { "Bob", "Joe", "Jim", "Sarah", "Tracy", "Vonda", "Robyn", "Dave", "Mike" };
            string[] messages = { "Hello", "This is a test", "I'm on a plane", "I'm in the airport" };
            Random r = new Random(DateTime.Now.Second);

            string userName = names[r.Next(names.Length - 1)];
            string message = messages[r.Next(messages.Length - 1)];

            Models.WallMessage genMsg = new Models.WallMessage();
            genMsg.UserDisplayName = userName;
            genMsg.Text = message;
            genMsg.MessageDateTime = DateTime.Now;
            genMsg.MessageId = System.Guid.NewGuid().ToString();

            System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo("C:\\Temp");
            System.IO.FileInfo[] files = dirInfo.GetFiles("*.jpg");

            if (files.Length > 0)
            {
                System.IO.FileInfo selectedFile = files[r.Next(files.Length - 1)];
                genMsg.UserImage = System.Drawing.Image.FromFile(selectedFile.FullName);
            }

            mMgr.AddMessage(genMsg);
        }
    }
}
